﻿using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;
using WeDonekRpc.Helper;
using WeDonekRpc.Helper.Config;

namespace Basic.UserCollect.Config
{
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class UserConfig : IUserConfig
    {
        private readonly IConfigSection _Config;
        public UserConfig (ISysConfig config)
        {
            this._Config = config.GetSection("User");
            this._Config.AddRefreshEvent(this._Refresh);
        }

        private void _Refresh (IConfigSection section, string name)
        {
            if (name == "PwdSign" || name.IsNull())
            {
                this.PwdSign = this._Config.GetValue<string>("PwdSign", "tc6xy3#%ay&ad");
            }
        }

        public string CalculatePwd (string password)
        {
            return string.Concat(password, "-", this.PwdSign).GetMd5().ToLower();
        }

        public string PwdSign
        {
            get;
            private set;
        }

        public string MiniAppType => "WxMini";
    }
}
